package com.cyz.web.app.concurrent;

/**
 * 多线程指令重排序
 */
public class OrderClient {

    public volatile static int a;

    public volatile static int b;

    public static void main(String[] args) {

        new Thread(() -> {
            int b = 1;
            int r2 = a;
        }).start();

        new Thread(() -> {
            int r1 = b;
            a = 2;
        }).start();

        try {
            Thread.sleep(500);
            System.out.printf("a=%s, b=%s \n", a, b);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
